<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'event-form',
	'enableClientValidation'=>false,
	'clientOptions'=>array(
		'validateOnSubmit'=>true,
	),
	'htmlOptions'=>array(
		'class'=>'',
		'enctype'=>'multipart/form-data'
	),
)); ?>
<?php $countries = array("Việt Nam" => "Việt Nam", "Afghanistan" => "Afghanistan", "Albania" => "Albania", "Algeria" => "Algeria", "American Samoa" => "American Samoa", "Andorra" => "Andorra", "Angola" => "Angola", "Anguilla" => "Anguilla", "Antarctica" => "Antarctica", "Antigua and Barbuda" => "Antigua and Barbuda", "Argentina" => "Argentina", "Armenia" => "Armenia", "Aruba" => "Aruba", "Australia" => "Australia", "Austria" => "Austria", "Azerbaijan" => "Azerbaijan", "Bahamas" => "Bahamas", "Bahrain" => "Bahrain", "Bangladesh" => "Bangladesh", "Barbados" => "Barbados", "Belarus" => "Belarus", "Belgium" => "Belgium", "Belize" => "Belize", "Benin" => "Benin", "Bermuda" => "Bermuda", "Bhutan" => "Bhutan", "Bolivia" => "Bolivia", "Bosnia and Herzegovina" => "Bosnia and Herzegovina", "Botswana" => "Botswana", "Bouvet Island" => "Bouvet Island", "Brazil" => "Brazil", "British Indian Ocean Territory" => "British Indian Ocean Territory", "Brunei Darussalam" => "Brunei Darussalam", "Bulgaria" => "Bulgaria", "Burkina Faso" => "Burkina Faso", "Burundi" => "Burundi", "Cambodia" => "Cambodia", "Cameroon" => "Cameroon", "Canada" => "Canada", "Cape Verde" => "Cape Verde", "Cayman Islands" => "Cayman Islands", "Central African Republic" => "Central African Republic", "Chad" => "Chad", "Chile" => "Chile", "China" => "China", "Christmas Island" => "Christmas Island", "Cocos (Keeling) Islands" => "Cocos (Keeling) Islands", "Colombia" => "Colombia", "Comoros" => "Comoros", "Congo" => "Congo", "Congo, The Democratic Republic of The" => "Congo, The Democratic Republic of The", "Cook Islands" => "Cook Islands", "Costa Rica" => "Costa Rica", "Cote D'ivoire" => "Cote D'ivoire", "Croatia" => "Croatia", "Cuba" => "Cuba", "Cyprus" => "Cyprus", "Czech Republic" => "Czech Republic", "Denmark" => "Denmark", "Djibouti" => "Djibouti", "Dominica" => "Dominica", "Dominican Republic" => "Dominican Republic", "Ecuador" => "Ecuador", "Egypt" => "Egypt", "El Salvador" => "El Salvador", "Equatorial Guinea" => "Equatorial Guinea", "Eritrea" => "Eritrea", "Estonia" => "Estonia", "Ethiopia" => "Ethiopia", "Falkland Islands (Malvinas)" => "Falkland Islands (Malvinas)", "Faroe Islands" => "Faroe Islands", "Fiji" => "Fiji", "Finland" => "Finland", "France" => "France", "French Guiana" => "French Guiana", "French Polynesia" => "French Polynesia", "French Southern Territories" => "French Southern Territories", "Gabon" => "Gabon", "Gambia" => "Gambia", "Georgia" => "Georgia", "Germany" => "Germany", "Ghana" => "Ghana", "Gibraltar" => "Gibraltar", "Greece" => "Greece", "Greenland" => "Greenland", "Grenada" => "Grenada", "Guadeloupe" => "Guadeloupe", "Guam" => "Guam", "Guatemala" => "Guatemala", "Guinea" => "Guinea", "Guinea-bissau" => "Guinea-bissau", "Guyana" => "Guyana", "Haiti" => "Haiti", "Heard Island and Mcdonald Islands" => "Heard Island and Mcdonald Islands", "Holy See (Vatican City State)" => "Holy See (Vatican City State)", "Honduras" => "Honduras", "Hong Kong" => "Hong Kong", "Hungary" => "Hungary", "Iceland" => "Iceland", "India" => "India", "Indonesia" => "Indonesia", "Iran, Islamic Republic of" => "Iran, Islamic Republic of", "Iraq" => "Iraq", "Ireland" => "Ireland", "Israel" => "Israel", "Italy" => "Italy", "Jamaica" => "Jamaica", "Japan" => "Japan", "Jordan" => "Jordan", "Kazakhstan" => "Kazakhstan", "Kenya" => "Kenya", "Kiribati" => "Kiribati", "Korea, Democratic People's Republic of" => "Korea, Democratic People's Republic of", "Korea, Republic of" => "Korea, Republic of", "Kuwait" => "Kuwait", "Kyrgyzstan" => "Kyrgyzstan", "Lao People's Democratic Republic" => "Lao People's Democratic Republic", "Latvia" => "Latvia", "Lebanon" => "Lebanon", "Lesotho" => "Lesotho", "Liberia" => "Liberia", "Libyan Arab Jamahiriya" => "Libyan Arab Jamahiriya", "Liechtenstein" => "Liechtenstein", "Lithuania" => "Lithuania", "Luxembourg" => "Luxembourg", "Macao" => "Macao", "Macedonia, The Former Yugoslav Republic of" => "Macedonia, The Former Yugoslav Republic of", "Madagascar" => "Madagascar", "Malawi" => "Malawi", "Malaysia" => "Malaysia", "Maldives" => "Maldives", "Mali" => "Mali", "Malta" => "Malta", "Marshall Islands" => "Marshall Islands", "Martinique" => "Martinique", "Mauritania" => "Mauritania", "Mauritius" => "Mauritius", "Mayotte" => "Mayotte", "Mexico" => "Mexico", "Micronesia, Federated States of" => "Micronesia, Federated States of", "Moldova, Republic of" => "Moldova, Republic of", "Monaco" => "Monaco", "Mongolia" => "Mongolia", "Montserrat" => "Montserrat", "Morocco" => "Morocco", "Mozambique" => "Mozambique", "Myanmar" => "Myanmar", "Namibia" => "Namibia", "Nauru" => "Nauru", "Nepal" => "Nepal", "Netherlands" => "Netherlands", "Netherlands Antilles" => "Netherlands Antilles", "New Caledonia" => "New Caledonia", "New Zealand" => "New Zealand", "Nicaragua" => "Nicaragua", "Niger" => "Niger", "Nigeria" => "Nigeria", "Niue" => "Niue", "Norfolk Island" => "Norfolk Island", "Northern Mariana Islands" => "Northern Mariana Islands", "Norway" => "Norway", "Oman" => "Oman", "Pakistan" => "Pakistan", "Palau" => "Palau", "Palestinian Territory, Occupied" => "Palestinian Territory, Occupied", "Panama" => "Panama", "Papua New Guinea" => "Papua New Guinea", "Paraguay" => "Paraguay", "Peru" => "Peru", "Philippines" => "Philippines", "Pitcairn" => "Pitcairn", "Poland" => "Poland", "Portugal" => "Portugal", "Puerto Rico" => "Puerto Rico", "Qatar" => "Qatar", "Reunion" => "Reunion", "Romania" => "Romania", "Russian Federation" => "Russian Federation", "Rwanda" => "Rwanda", "Saint Helena" => "Saint Helena", "Saint Kitts and Nevis" => "Saint Kitts and Nevis", "Saint Lucia" => "Saint Lucia", "Saint Pierre and Miquelon" => "Saint Pierre and Miquelon", "Saint Vincent and The Grenadines" => "Saint Vincent and The Grenadines", "Samoa" => "Samoa", "San Marino" => "San Marino", "Sao Tome and Principe" => "Sao Tome and Principe", "Saudi Arabia" => "Saudi Arabia", "Senegal" => "Senegal", "Serbia and Montenegro" => "Serbia and Montenegro", "Seychelles" => "Seychelles", "Sierra Leone" => "Sierra Leone", "Singapore" => "Singapore", "Slovakia" => "Slovakia", "Slovenia" => "Slovenia", "Solomon Islands" => "Solomon Islands", "Somalia" => "Somalia", "South Africa" => "South Africa", "South Georgia and The South Sandwich Islands" => "South Georgia and The South Sandwich Islands", "Spain" => "Spain", "Sri Lanka" => "Sri Lanka", "Sudan" => "Sudan", "Suriname" => "Suriname", "Svalbard and Jan Mayen" => "Svalbard and Jan Mayen", "Swaziland" => "Swaziland", "Sweden" => "Sweden", "Switzerland" => "Switzerland", "Syrian Arab Republic" => "Syrian Arab Republic", "Taiwan, Province of China" => "Taiwan, Province of China", "Tajikistan" => "Tajikistan", "Tanzania, United Republic of" => "Tanzania, United Republic of", "Thailand" => "Thailand", "Timor-leste" => "Timor-leste", "Togo" => "Togo", "Tokelau" => "Tokelau", "Tonga" => "Tonga", "Trinidad and Tobago" => "Trinidad and Tobago", "Tunisia" => "Tunisia", "Turkey" => "Turkey", "Turkmenistan" => "Turkmenistan", "Turks and Caicos Islands" => "Turks and Caicos Islands", "Tuvalu" => "Tuvalu", "Uganda" => "Uganda", "Ukraine" => "Ukraine", "United Arab Emirates" => "United Arab Emirates", "United Kingdom" => "United Kingdom", "United States" => "United States", "United States Minor Outlying Islands" => "United States Minor Outlying Islands", "Uruguay" => "Uruguay", "Uzbekistan" => "Uzbekistan", "Vanuatu" => "Vanuatu", "Venezuela" => "Venezuela", "Viet Nam" => "Viet Nam", "Virgin Islands, British" => "Virgin Islands, British", "Virgin Islands, U.S." => "Virgin Islands, U.S.", "Wallis and Futuna" => "Wallis and Futuna", "Western Sahara" => "Western Sahara", "Yemen" => "Yemen", "Zambia" => "Zambia", "Zimbabwe" => "Zimbabwe"); ?>
<div class="row">
	<div class="col-xs-12">
		<h2>Đăng sự kiện trên <strong>NextTopEvent</strong></h2>
    </div>
	<div class="col-xs-8 form-horizontal">
    	<fieldset>
        	<legend>Thông tin sự kiện</legend>
    	<!-- Event Title -->
		<div class="form-group">
        	<?php echo $form->labelEx($model, 'title', array('class'=>'control-label col-xs-2')); ?>
            <div class="col-xs-10">
            	<?php echo $form->textField($model, 'title', array('class'=>'form-control input-sm', 'placeholder'=>'Điền tên sự kiện của bạn')); ?>
                <?php echo $form->error($model, 'title'); ?>
            </div>
        </div>
        <!-- Event Category & Event ticket -->
        <div class="form-group">
            <?php echo $form->labelEx($model->eventCategory, 'category_id', array('class'=>'control-label col-xs-2')); ?>
            <div class="col-xs-5">
            	<?php echo $form->dropDownList($model->eventCategory,'category_id',CHtml::listData(Categories::model()->findAll(),'id','title', 'category.title'), array('class'=>'form-control input-sm')); ?>
            </div>
            <?php echo $form->labelEx($model, 'ticket', array('class'=>'control-label col-xs-2')); ?>
            <div class="col-xs-3">
                <?php echo $form->dropDownList($model,'ticket', array('F'=>'Miễn phí', 'P'=>'Có phí', 'G'=>'Ưu đãi'), array('class'=>'form-control input-sm')); ?>
            </div>
        </div>
        <div class="form-group">
            <?php echo $form->labelEx($model, 'brief', array('class'=>'control-label col-xs-2')); ?>
            <div class="col-xs-10">
            	<?php echo $form->textArea($model, 'brief', array('class'=>'form-control', 'rows'=>5, 'placeholder'=>'Mô tả tóm tắt thông tin về sự kiện')); ?>
                <?php echo $form->error($model, 'brief'); ?>
            </div>
        </div>
        </fieldset>
        <fieldset>
        	<legend>Địa điểm sự kiện</legend>
        <!-- Event Location -->
        <div class="form-group">
        	<?php echo $form->labelEx($model->location, 'title', array('class'=>'control-label col-xs-2')); ?>
            <div class="col-xs-10">
                <?php echo $form->textField($model->location, 'title', array('class'=>'form-control input-sm', 'placeholder'=>'Địa điểm tổ chức')); ?>
                
            </div>
        </div>
        <div class="form-group">
        	<?php echo $form->labelEx($model->location, 'address', array('class'=>'control-label col-xs-2')); ?>
            <div class="col-xs-10">
                <?php echo $form->textField($model->location, 'address', array('class'=>'form-control input-sm', 'placeholder'=>'Địa chỉ')); ?>
                
            </div>
        </div>
        <div class="form-group">
            <div class="col-xs-5 col-xs-offset-2">
	        	<?php echo $form->textField($model->location, 'ward', array('class'=>'form-control input-sm', 'placeholder'=>'Phường/Xã')); ?>
            </div>
            <div class="col-xs-5">
	        	<?php echo $form->textField($model->location, 'district', array('class'=>'form-control input-sm', 'placeholder'=>'Quận/Huyện')); ?>
            </div>
        </div>
        <div class="form-group">
            <div class="col-xs-5 col-xs-offset-2">
	        	<?php echo $form->textField($model->location, 'city', array('class'=>'form-control input-sm', 'placeholder'=>'Tỉnh/Thành phố')); ?>
            </div>
            <div class="col-xs-5">
                <?php echo $form->dropDownList($model->location, 'country', $countries, array('class'=>'form-control input-sm')); ?>
            </div>
        </div>
        <!-- Event Time -->
        <div class="form-group">
            <label for="inputEmail3" class="col-xs-2 control-label">Thời gian</label>
            <label for="inputEmail3" class="col-xs-5 control-label pull-left">Thời gian bắt đầu</label>
            <label for="inputEmail3" class="col-xs-5 control-label pull-left">Thời gian kết thúc</label>
            <div class="col-xs-offset-2 col-xs-5 form-inline">
            	<div class="col-xs-7">
                    <div class="form-group input-icon right bootstrap-datepicker">
                        <span class="glyphicon glyphicon-calendar"></span>
                        <input type="text" class="form-control" placeholder="Left icon" id="startdate" name="startdate" value="<?php echo date('d-m-Y', strtotime($model->startdate)); ?>">
                    </div>
                </div>
                <div class="col-xs-5">
                    <div class="form-group input-icon right bootstrap-timepicker">
                        <span class="glyphicon glyphicon-time"></span>
                        <input type="text" class="form-control" placeholder="Left icon" id="starttime" name="starttime" value="<?php echo date('H:i', strtotime($model->startdate)); ?>">
                    </div>
                </div>
            </div>
            <div class="col-xs-5 form-inline">
            	<div class="col-xs-7">
                    <div class="form-group input-icon right bootstrap-datepicker">    
                        <span class="glyphicon glyphicon-calendar"></span>
                        <input type="text" class="form-control" placeholder="Left icon" id="enddate" name="enddate" value="<?php echo date('d-m-Y', strtotime($model->enddate)); ?>">
    
                    </div>
                </div>
                <div class="col-xs-5">
                    <div class="form-group input-icon right bootstrap-timepicker">
                        <span class="glyphicon glyphicon-time"></span>
                        <input type="text" class="form-control" placeholder="Left icon" id="endtime" name="endtime" value="<?php echo date('H:i', strtotime($model->enddate)); ?>">
    
                    </div>
                </div>
            </div>
        </div>
        </fieldset>
        <fieldset>
        	<legend>Thông tin liên hệ<small class="pull-right"><a id="add-contact" href="javascript::void(0)">Thêm thông tin liên hệ</a></small></legend>
            <!-- Event Contact -->
            <?php foreach ($model->contacts as $x => $contact): ?>
            <div class="form-contact" id="contact-<?php echo ($x+1); ?>">
            	<input type="hidden" name="EventContact[id][]" id="EventContact[id]" value="<?php echo $contact->id; ?>" class="contact-id" />
                <div class="form-group">
                    <?php echo $form->labelEx($contact, 'company', array('class'=>'control-label col-xs-2')); ?>
                    <div class="col-xs-9">
                        <input type="text" class="form-control input-sm" placeholder="Đơn vị liên lạc" name="EventContact[company][]" id="EventContact[company]" value="<?php echo $contact->company; ?>" />
                    </div>
                    <div class="col-xs-1 contact-button">
                    	<a class="btn btn-default btn-block" data-id="<?php echo ($x+1); ?>">Xóa</a>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-xs-2 col-xs-offset-2">
                        <select name="EventContact[prename][]" id="EventContact[prename]" class="form-control input-sm">
                        	<option value="Mr." <?php if ($contact->prename === 'Mr.') echo 'selected'; ?>>Mr.</option>
							<option value="Miss." <?php if ($contact->prename === 'Miss.') echo 'selected'; ?>>Miss.</option>
                            <option value="Mrs." <?php if ($contact->prename === 'Mrs.') echo 'selected'; ?>>Mrs.</option>
                        </select>
                    </div>
                    <div class="col-xs-4">
                        <input type="text" class="form-control input-sm" placeholder="Họ và tên" name="EventContact[fullname][]" id="EventContact[fullname]" value="<?php echo $contact->fullname; ?>" />
                    </div>
                    <div class="col-xs-4">
                        <input type="text" class="form-control input-sm" placeholder="Số điện thoại" name="EventContact[phone][]" id="EventContact[phone]" value="<?php echo $contact->phone; ?>" />
                    </div>
                </div>
            </div>
            <?php endforeach; ?>
            <div id="form-contact" data-id="<?php echo count($model->contacts); ?>" style="display:none;">
                <div class="form-group">
                    <?php echo $form->labelEx($contact, 'company', array('class'=>'control-label col-xs-2')); ?>
                    <div class="col-xs-9">
                        <input type="text" class="form-control input-sm" placeholder="Đơn vị liên lạc" name="EventContact[company][]" id="EventContact[company]" />
                    </div>
                    <div class="col-xs-1 contact-button">
                    	<a class="btn btn-default btn-block" data-id="0">Xóa</a>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-xs-2 col-xs-offset-2">
                        <select name="EventContact[prename][]" id="EventContact[prename]" class="form-control input-sm">
                        	<option value="Mr.">Mr.</option>
							<option value="Miss.">Miss.</option>
                            <option value="Mrs.">Mrs.</option>
                        </select>
                    </div>
                    <div class="col-xs-4">
                        <input type="text" class="form-control input-sm" placeholder="Họ và tên" name="EventContact[fullname][]" id="EventContact[fullname]" />
                    </div>
                    <div class="col-xs-4">
                        <input type="text" class="form-control input-sm" placeholder="Số điện thoại" name="EventContact[phone][]" id="EventContact[phone]" />
                    </div>
                </div>
            </div>
        </fieldset>
	</div>
    <div class="col-xs-4">
    	<fieldset>
        	<legend>Ảnh đại diện sự kiện</legend>
            <!-- Event Image -->
            <div class="fileinput fileinput-new btn-block" data-provides="fileinput">
            	<div class="fileinput-new thumbnail" style="width:100%;">
                	<img src="<?php echo IMAGES_URL . 'events/primary/' . date('Ymd', strtotime($model->posteddate)) . '/' . $model->image; ?>" alt="...">
                </div>
                <div class="fileinput-preview fileinput-exists thumbnail" style=""></div>
                <div>
                    <span class="btn btn-default btn-file btn-block"><span class="fileinput-new">Đổi ảnh sự kiện</span><span class="fileinput-exists">Chọn ảnh khác</span>
                    <?php echo $form->fileField($model, 'image', array('class'=>'default')); ?>
                    </span>
                    <a href="#" class="btn btn-default fileinput-exists btn-block" data-dismiss="fileinput">Xóa bỏ ảnh hiện tại</a>
                </div>
            </div>
        </fieldset>
        
        <fieldset>
        	<legend>Sơ đồ chỗ ngồi</legend>
            <!-- Event Image -->
            <div class="fileinput fileinput-new btn-block" data-provides="fileinput">
            	<?php if (!empty($model->chart)) : ?>
                	<div class="fileinput-new thumbnail" style="width:100%;">
                        <img src="<?php echo IMAGES_URL . 'charts/' . date('Ymd', strtotime($model->posteddate)) . '/' . $model->chart->image; ?>" alt="...">
                    </div>
            	<?php endif; ?>
                <div class="fileinput-preview fileinput-exists thumbnail" style=""></div>
                <div>
                    <span class="btn btn-default btn-file btn-block"><span class="fileinput-new">Chọn ảnh sơ đồ chỗ ngồi</span><span class="fileinput-exists">Chọn ảnh khác</span>
                    <?php echo $form->fileField($chart, 'image', array('class'=>'default')); ?>
                    </span>
                    <a href="#" class="btn btn-default fileinput-exists btn-block" data-dismiss="fileinput">Xóa bỏ ảnh hiện tại</a>
                </div>
            </div>
        </fieldset>
        <fieldset id="form-ticket" <?php if ($model->ticket === 'F') { echo 'style="display:none;"'; } ?>>
        	<legend>Vé sự kiện<small class="pull-right"><a id="add-ticket" href="javascript:void(0)">Thêm</a></small></legend>
            <!-- Event Image -->
            <?php foreach ($model->tickets as $x => $ticket) : ?>
            <div class="form-ticket" id="ticket-<?php echo ($x+1); ?>">
            	<input type="hidden" name="EventTickets[id][]" id="EventTickets[id]" value="<?php echo $ticket->id; ?>" class="ticket-id" />
                <div class="form-group row">
                    <div class="col-xs-5 ticket-title">
                        <input type="text" class="form-control input-sm" placeholder="Loại vé" name="EventTickets[title][]" id="EventTickets[title]" value="<?php echo $ticket->title; ?>" />
                    </div>
                    <div class="col-xs-5 ticket-price input-icon right">
                    	<span class="">VNĐ</span>
                        <input type="text" class="form-control input-sm text-right" placeholder="Giá vé" name="EventTickets[price][]" id="EventTickets[price]" value="<?php echo number_format($ticket->price, 0, ',', ''); ?>" />
                    </div>
                    <div class="col-xs-2 ticket-button">
                    	<a class="btn btn-default btn-block" data-id="<?php echo ($x+1); ?>">Xóa</a>
                    </div>
                </div>
            </div>
            <?php endforeach; ?>
            <div id="ticket-content" data-id="<?php echo count($model->tickets); ?>" style="display:none;">
                <div class="form-group row">
                    <div class="col-xs-5 ticket-title">
                        <input type="text" class="form-control input-sm" placeholder="Loại vé" name="EventTickets[title][]" id="EventTickets[title]" />
                    </div>
                    <div class="col-xs-5 ticket-price input-icon right">
                    	<span class="">VNĐ</span>
                        <input type="text" class="form-control input-sm text-right" placeholder="Giá vé" name="EventTickets[price][]" id="EventTickets[price]" />
                    </div>
                    <div class="col-xs-2 ticket-button">
                    	<a class="btn btn-default btn-block" data-id="0">Xóa</a>
                    </div>
                </div>
            </div>
        </fieldset>
        
        <fieldset>
            <legend>Tags</legend>
            
            <div class="form-group">
                <?php $labels = '';
                foreach ($model->label as $data) {
                    $labels .= $data->id . ':' . $data->title . ',';
                } ?>
                <?php echo $form->hiddenField($label, 'title', array('class'=>'form-control select2 input-sm', 'value'=>substr($labels, 0, -1))); ?>
             </div>
            <span class="help-block">Các tag ngăn cách nhau bằng dấu phẩy ",".</span>
        </fieldset>
    </div>
</div>
<div class="row">
    <div class="col-xs-12">
        <fieldset>
                <legend>Nội dung sự kiện</legend>
        <div class="form-group">
            <?php $this->widget('application.extensions.ckeditor.CKEditor', array(
                'model'=>$model->content,
                'attribute'=>'description',
                'language'=>'vi',
                'editorTemplate'=>'full',
                'options' => array(
					'height'=>'400px',
				),
                'htmlOptions'=>array('rows'=>20,'class'=>'form-control'),
            )); ?>
            <?php echo $form->error($model->content, 'description', array('class'=>'help-block')); ?>
        </div>
        </fieldset>
	</div>
    <div class="col-xs-12">
	    <button type="submit" class="btn btn-create pull-right" onclick="$('.loader').show();">Cập nhật sự kiện</button>
    </div>
</div>
<?php $this->endWidget(); ?>
<script type="text/javascript">
$(document).ready(function(e) {
    $('#startdate').datepicker({
		format: 'dd-mm-yyyy',
	}).on('changeDate', function(ev){
		$('#startdate').datepicker('hide');
	});
	$('#enddate').datepicker({
		format: 'dd-mm-yyyy',
	}).on('changeDate', function(ev){
		$('#enddate').datepicker('hide');
	});
	$('#starttime').timepicker({
		defaultTime: '<?php echo date('H:i', strtotime($model->startdate)); ?>',
		showMeridian: false
	});
	$('#endtime').timepicker({
		defaultTime: '<?php echo date('H:i', strtotime($model->enddate)); ?>',
		showMeridian: false
	});
	
	// Ticket form
	$('#Events_ticket').on('change', function(){
		var ticket = $(this).val();
		if (ticket != 'F') {
			$('#form-ticket').fadeIn();
		}
		else {
			$('#form-ticket').hide();
		}
	});
	var totalTicket = $('.form-ticket').size();
	$('#add-ticket').on('click', function(){
		var form = $('#ticket-content').html();
		var count = $('#ticket-content').data('id');
		if (totalTicket < 10) {
			$('#ticket-content').before('<div class="form-ticket" id="ticket-'+(count+1)+'">'+form+'</div>').data('id', (count+1));
			totalTicket++;
			$('#ticket-'+(count+1)+' .ticket-button a').data('id', count+1);
			
			$('#ticket-'+(count+1)+' .ticket-button a').on('click', function() {
				var id = $(this).data('id');
				if (confirm('Bạn muốn xóa vé này đi?')) {
					// Request remove ticket database
					var ticket = $('#ticket-'+id+' .ticket-id').val();
					if (ticket != undefined) {
						$.ajax({
							url: '<?php echo Yii::app()->createUrl('/Events/request/deleteTicket'); ?>',
							type: 'post',
							data: {
								id: ticket,
							},
							success: function() {
								$('#ticket-'+id).fadeOut();
								totalTicket--;
							}
						});
					}
					else {
						$('#ticket-'+id).fadeOut();
						totalTicket--;
					}
				}
			});
		}
	});
	// Delete ticket
	$('.ticket-button a').on('click', function() {
		var id = $(this).data('id');
		if (confirm('Bạn muốn xóa vé này đi?')) {
			// Request remove ticket database
			var ticket = $('#ticket-'+id+' .ticket-id').val();
			if (ticket != undefined) {
				$.ajax({
					url: '<?php echo Yii::app()->createUrl('/Events/request/deleteTicket'); ?>',
					type: 'post',
					data: {
						id: ticket,
					},
					success: function() {
						$('#ticket-'+id).fadeOut();
						totalTicket--;
					}
				});
			}
			else {
				$('#ticket-'+id).fadeOut();
				totalTicket--;
			}
		}
	});
	
	// Contact form
	var totalContact = $('.form-contact').size();
	$('#add-contact').on('click', function(){
		var form = $('#form-contact').html();
		var count = $('#form-contact').data('id');
		if (totalContact < 4) {
			$('#form-contact').after('<div class="form-contact" id="contact-'+(count+1)+'">'+form+'</div>').data('id', (count+1));
			totalContact++;
			
			$('#contact-'+(count+1)+' .contact-button a').data('id', count+1);
			
			$('#contact-'+(count+1)+' .contact-button a').on('click', function() {
				var id = $(this).data('id');
				if (confirm('Bạn muốn xóa liên hệ này đi?')) {
					// Request remove ticket database
					var contact = $('#contact-'+id+' .contact-id').val();
					if (contact != undefined) {
						$.ajax({
							url: '<?php echo Yii::app()->createUrl('/Events/request/deleteContact'); ?>',
							type: 'post',
							data: {
								id: contact,
							},
							success: function() {
								$('#contact-'+id).fadeOut();
								totalContact--;
							}
						});
					}
					else {
						$('#contact-'+id).fadeOut();
						totalContact--;
					}
				}
			});
		}
	});
	// Delete contact
	$('.contact-button a').on('click', function() {
		var id = $(this).data('id');
		if (confirm('Bạn muốn xóa liên hệ này đi?')) {
			// Request remove ticket database
			var contact = $('#contact-'+id+' .contact-id').val();
			if (contact != undefined) {
				$.ajax({
					url: '<?php echo Yii::app()->createUrl('/Events/request/deleteContact'); ?>',
					type: 'post',
					data: {
						id: contact,
					},
					success: function() {
						$('#contact-'+id).fadeOut();
						totalContact--;
					}
				});
			}
			else {
				$('#contact-'+id).fadeOut();
				totalContact--;
			}
		}
	});
	
});
</script>